<template>
	<div class="checkExceptionDetail">
		<el-breadcrumb class="breadcrumb" separator="/">
			<el-breadcrumb-item :to="{ path: '/check' }">我的审核</el-breadcrumb-item>
			<el-breadcrumb-item>通融审核</el-breadcrumb-item>
		</el-breadcrumb>
		<div class="footer-content">
			<el-button v-show="isCheck" class="custom-button-minor toLeft" @click="cancal">取消</el-button>
			<el-button v-show="isCheck" type="primary" class="toLeft" :disabled="isFirstSubmit==true" @click="submit">提交</el-button>
			<el-button v-show="!isCheck" @click="isCheck=true" type="primary">审核</el-button>
		</div>
		<div class="info-content">
			<steps ref="steps"></steps>
			<hr class="hrDefault">
			<el-tabs class="info-tabs" v-model="activeName" @tab-click="$libs.scrollTop('.el-tabs__content')">
				<template v-for="vm in tapList">
					<el-tab-pane class="info-temp" :label="vm.name" :name="'tap'+vm.index">
						<div v-if="vm.temp=='attachment'" :is="vm.temp" :ref="vm.temp" @submit-attachmentHad="attachHave"></div>
						<div v-else :is="vm.temp" :ref="vm.temp"></div>
					</el-tab-pane>
				</template>
			</el-tabs>
		</div>
		<div class="submitContent submitContentTwo" v-show="isCheck">
			<i @click="isCheck=false" class="el-icon-arrow-down arrow-down"></i>
			<el-row class="info-row">
				<el-col :span="2" class="subTitle">
					审核意见
				</el-col>
				<el-col :span="18">
					<el-input class="info-textarea" :rows="3" type="textarea" placeholder="请输入" v-model="submitInfo.suggess"></el-input>
				</el-col>
			</el-row>
			<el-row class="info-row">
				<el-col :span="2" class="subTitle">
					GPS
				</el-col>
				<el-col :span="18" class="radioContent">
					<el-radio class="radio" v-model="submitInfo.isGps" label='true'>需要</el-radio>
					<el-radio class="radio" v-model="submitInfo.isGps" label="false">不需要</el-radio>
				</el-col>
			</el-row>
			<el-row class="info-row">
				<el-col :span="2" class="subTitle">
					审核结果
				</el-col>
				<el-col :span="18" class="radioContent">
					<el-radio class="radio" v-model="submitInfo.isCheck" label="1">同意</el-radio>
					<el-radio class="radio" v-model="submitInfo.isCheck" label="0">不同意</el-radio>
					<el-radio class="radio" v-model="submitInfo.isCheck" label="2">提交上级</el-radio>
				</el-col>
			</el-row>
		</div>
	</div>
</template>
<script>
export default {
	name: 'checkExceptionDetail',
	components: {
		credit: require('../../components/order/credit'),
		customInfo: require('../../components/order/customInfo'),
		carBuyCommon: require('../../components/order/carBuyCommon'),
		assurePerson: require('../../components/order/assurePerson'),
		carAndCredit: require('../../components/order/carAndCredit'),
		attachment: require('../../components/order/attachment'),
		checkInfo: require('../../components/order/checkInfo'),
		historyLoan: require('../../components/order/historyLoan'),
		steps: require('../../components/other/steps')
	},
	data() {
		return {
			orderNo: this.$route.query.orderNo,
			annexBatchNo: this.$route.query.annexBatchNo,
			customerIdCard: this.$route.query.customerIdCard,
			applyId: this.$route.query.applyId,
			applyType: this.$route.query.applyType,
			flowNodeId: this.$route.query.flowNodeId,
			taskId: this.$route.query.taskId,
			bizChannel: this.$route.query.bizChannel,
			orderStatus: this.$route.query.orderStatus,
			isCheck: false,
			tapNumEdit: 0,
			isFirstSubmit: false,
			activeName: 'tap0',
			tapList: [
				{ name: '征信结果', index: 0, temp: 'credit', show: true },
				{ name: '客户信息', index: 1, temp: 'customInfo', show: true },
				{ name: '共同购车人', index: 2, temp: 'carBuyCommon', show: true },
				{ name: '担保人', index: 3, temp: 'assurePerson', show: true },
				{ name: '车辆及贷款信息', index: 4, temp: 'carAndCredit', show: true },
				{ name: '审核信息', index: 10, temp: 'checkInfo', show: true },
				{ name: '附件', index: 5, temp: 'attachment', show: 'none' },
				{ name: '历史贷款记录', index: 6, temp: 'historyLoan', show: true },
			],
			submitInfo: {
				// analy: '',
				suggess: '',
				isGps: this.$route.query.needGps,
				isCheck: '',
				isCheckOther: false
			},
			isAttachHaveRun: false,
		}
	},
	watch: {
		tapNumEdit: function(_cur, _old) {
			console.log('tapNumEdit-' + _cur);
			if (_cur == 3) {
				console.log(this);
				for (var i = 0; i < this.tapList.length; i++) {
					if (this.tapList[i].show == false) {
						this.tapList.splice(i, 1);
						i--;
					}
				}
				this.tapNumEdit = 0;
				this.$nextTick(() => {
					this.getDataSecond();
				});
			}
		},
		deep: true
	},
	methods: {
		getDataSecond() {
			for (let i = 0; i < this.tapList.length; i++) {
				let el = this.tapList[i];
				switch (el.index) {
					case 6:
						this.$refs[el.temp][0].customerIdCard = this.customerIdCard;
						this.$refs[el.temp][0].getDate(this.orderNo);
						break;
					case 1:
						this.$refs[el.temp][0].getUserInfo(this.orderNo, this.isSubmit);
						break;
					case 2:
						this.$refs[el.temp][0].getInfo(this.orderNo, this.isSubmit);
						break;
					case 3:
						this.$refs[el.temp][0].getInfo(this.orderNo, this.isSubmit);
						break;
					case 4:
						this.$refs[el.temp][0].isGps = false;
						this.$refs[el.temp][0].getCarInfo(this.orderNo, this.isSubmit);
						this.$refs[el.temp][0].getLoanInfo(this.orderNo, this.isSubmit);
						break;
					case 5:
						this.$refs[el.temp][0].postDeal(this.orderNo, this.annexBatchNo);
						break;
					case 10:
						this.$refs[el.temp][0].getInfo(this.orderNo);
						break;
					default:
						break;
				}
			}
		},
		attachHave() {
			let ishaveAttach = false;
			for (var i = 0; i < this.tapList.length; i++) {
				if (this.tapList[i].index == 5) {
					ishaveAttach = true;
					this.tapList[i].show = true;
				}
			}
			if (!ishaveAttach) {
				this.tapList.push({ name: '附件', index: 5, temp: 'attachment', show: true });
			}
			this.isAttachHaveRun = true;
		},
		submit() {
			let param = {
				orderNo: this.orderNo,
				taskId: this.taskId,
				flowNodeId: this.flowNodeId,
				bizType: this.bizChannel,
				// needGps: this.submitInfo.isGps == 'false' ? false : true,
				approvalResult: this.submitInfo.isCheck,
				approvalRemark: this.submitInfo.suggess,
				applyType: this.applyType
			};
			if (param.approvalRemark.length > 200) {
				this.$message.error('审核意见字数过长，请控制在200字以内');
				return;
			}
			if (!this.$libs.mustWrite(param)) {
				this.$message('请把信息补充完整');
				return;
			}
			this.isFirstSubmit = true;
			this.$http.post('/submitTaskController/saveGPSInfo', {
				orderNo: this.orderNo,
				needGps: this.submitInfo.isGps == 'false' ? false : true
			}).then((data) => {
				if (data.data.success) {
					if (data.data.data == true) {
						this.submitEnd(param);
					} else {
						this.$message.error(data.data.message);
					}
				}
			}).catch((error) => {

			});

		},
		submitEnd(param) {
			this.$http.post('/submitTaskController/auditorSubmitTask', param).then((data) => {
				if (data.data.success) {
					this.$message({
						message: '审核成功！',
						type: 'success'
					});
					this.$router.push({ path: '/check' });
				} else {
					this.$message.error(data.data.message);
				}
			}).catch((error) => {

			});
		},
		cancal() {
			this.$confirm('是否确认取消?', '取消', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				this.$router.push({ path: '/check' });
			}).catch((error) => {});
		},
	},
	mounted() {
		// 默认获取征信信息-tap0
		this.$refs.attachment[0].postDeal(this.orderNo, this.annexBatchNo);
		this.$refs.attachment[0].show = false;
		this.$refs.steps.getCheckInfo(this.orderNo, this.orderStatus);
		this.tapNumEdit = 0;
		this.$refs.credit[0].getCreditInfo(this.orderNo, {
			carBuyCommon: () => {
				this.tapNumEdit++;
				console.log('tapList1');
			},
			assurePerson: () => {
				this.tapNumEdit++;
				console.log('tapList2');
			},
			carBuyCommonNone: () => {
				for (let i = 0; i < this.tapList.length; i++) {
					let val = this.tapList[i];
					if (val.index == 2) {
						val.show = false;
						console.log('tapList1');
						this.tapNumEdit++;
					}
				}

			},
			assurePersonNone: () => {
				for (let i = 0; i < this.tapList.length; i++) {
					let val = this.tapList[i];
					if (val.index == 3) {
						val.show = false;
						console.log('tapList2');
						this.tapNumEdit++;
					}
				}

			}
		});
		this.$refs.historyLoan[0].customerIdCard = this.customerIdCard;
		this.$refs.historyLoan[0].getDate(this.orderNo, () => {
			for (let i = 0; i < this.tapList.length; i++) {
				let val = this.tapList[i];
				if (val.index == 6) {
					val.show = false;
					console.log('tapList3');
					this.tapNumEdit++;
				}
			}

		}, () => {
			console.log('tapList31');
			this.tapNumEdit++;
		});

		if (this.orderStatus == 10) {
			this.isTip = true;
		}
	}
}

</script>
<style lang="scss" scoped>
@import '../../assets/css/site.scss';
.checkExceptionDetail {
	padding: 10px 16px;
	position: relative;
	.info-content {
		background: #fff;
		padding: 20px;
		position: absolute;
		top: 50px;
		left: 16px;
		right: 16px;
		bottom: 0;
		.info-temp {
			background: #fff;
			padding: 0px 20px 100px 20px;
			.credit,
			.customInfo,
			.carBuyCommon,
			.assurePerson,
			.carAndCredit,
			.creditEnter,
			.finance,
			.attachment,
			.assetProtection,
			.checkInfo,
			.checkModify {
				padding-right: 200px;
			}
		}
	}
	.footer-content {
		background: #fff;
		position: fixed;
		bottom: 0;
		left: 200px;
		right: 0px;
		height: 36px;
		padding: 12px 100px 12px 50px;
		border-top: 1px solid #e0e6ed;
		z-index: 1;
		text-align: center;
		.toLeft {
			float: left;
		}
	}
	.submitContent {
		background: #fff;
		position: fixed;
		bottom: 60px;
		left: 200px;
		right: 0px;
		height: 300px;
		padding: 30px 100px 0px 8px;
		border-top: 1px solid #e0e6ed;
		.radioContent {
			text-align: left;
			margin: 5px 0px 0px 12px;
		}
		.arrow-down {
			color: #20a0ff;
			position: absolute;
			right: 25px;
			top: 15px;
			cursor: pointer;
		}
		.checkbox {
			margin-left: 10px;
		}
	}
	.submitContentTwo {
		height: 200px;
	}
}

</style>
